package com.sc.nft.admin.rpc;

import com.sc.nft.admin.request.IdRequest;
import com.sc.nft.entity.req.*;
import com.sc.nft.entity.vo.*;
import com.sc.nft.service.DaoPledgeService;
import com.sc.nft.sup.PageResult;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @author 刘国航
 * @desc
 * @since 2024/11/27 10:30
 */
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/rpc/daoPledge")
@Api(tags = "销毁质押接口")
public class DaoPledgeRpc {

    private final DaoPledgeService daoPledgeService;

    @ApiOperation(value = "新建销毁质押活动", notes = "新建销毁质押活动", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/create", produces = MediaType.APPLICATION_JSON_VALUE)
    public Result create(@RequestBody @Valid DaoPledgeCreateRequest request) {
        daoPledgeService.create(request);
        return Result.success();
    }

    @ApiOperation(value = "修改销毁质押活动", notes = "修改销毁质押活动", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/update", produces = MediaType.APPLICATION_JSON_VALUE)
    public Result update(@RequestBody @Valid DaoPledgeUpdateRequest request) {
        daoPledgeService.update(request);
        return Result.success();
    }

    @ApiOperation(value = "更新上下架状态", notes = "更新上下架状态", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/updateStatus", produces = MediaType.APPLICATION_JSON_VALUE)
    public Result updateStatus(@RequestBody @Valid DaoPledgeUpdateStatusRequest request) {
        daoPledgeService.updateStatus(request.getId(), request.getStatus());
        return Result.success();
    }

    @ApiOperation(value = "分页查询", notes = "分页查询", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/page", produces = MediaType.APPLICATION_JSON_VALUE)
    public PageResult<DaoPledgeCommercialVO> page(@RequestBody @Valid DaoPledgePageRequest request) {
        return PageResult.success(daoPledgeService.page(request.toMp(), request.getDaoId(), request.getName()));
    }

    @ApiOperation(value = "详情", notes = "分页查询", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/detail", produces = MediaType.APPLICATION_JSON_VALUE)
    public Result<DaoPledgeDetailCommercialVO> detail(@RequestBody @Valid IdRequest request) {
        return Result.success(daoPledgeService.detail(request.getId()));
    }

    @ApiOperation(value = "共创记录分页查询", notes = "共创记录分页查询", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/userPeriodsPage", produces = MediaType.APPLICATION_JSON_VALUE)
    public PageResult<DaoPledgeUserPeriodsVO> userPeriodsPage(@RequestBody @Valid DaoPledgeUserPeriodsPageRequest request) {
        return PageResult.success(daoPledgeService.userPeriodsPage(request.toMp(), request.getDaoId(), request.getUserTel(), request.getName(), request.getPeriods()));
    }

    @ApiOperation(value = "共创记录详情", notes = "共创记录详情", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/userPeriodsDetail", produces = MediaType.APPLICATION_JSON_VALUE)
    public Result<List<DaoPledgeUserPeriodsDetailVO>> userPeriodsDetail(@RequestBody @Valid IdRequest request) {
        return Result.success(daoPledgeService.userPeriodsDetail(request.getId()));
    }

    @ApiOperation(value = "奖励记录分页查询", notes = "奖励记录分页查询", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/rewardPeriodsPage", produces = MediaType.APPLICATION_JSON_VALUE)
    public PageResult<DaoPledgeRewardPeriodsVO> rewardPeriodsPage(@RequestBody @Valid DaoPledgeUserPeriodsPageRequest request) {
        return PageResult.success(daoPledgeService.rewardPeriodsPage(request.toMp(), request.getDaoId(), request.getUserTel(), request.getName(), request.getPeriods()));
    }

    @ApiOperation(value = "奖励记录详情", notes = "奖励记录详情", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/rewardPeriodsDetail", produces = MediaType.APPLICATION_JSON_VALUE)
    public Result<List<DaoPledgeRewardPeriodsDetailVO>> rewardPeriodsDetail(@RequestBody @Valid IdRequest request) {
        return Result.success(daoPledgeService.rewardPeriodsDetail(request.getId()));
    }

    @ApiOperation(value = "直推结算记录分页查询", notes = "直推结算记录分页查询", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/directPushPage", produces = MediaType.APPLICATION_JSON_VALUE)
    public PageResult<DaoPledgeDirectPushVO> directPushPage(@RequestBody @Valid DaoPledgeDirectPushRequest request) {
        return PageResult.success(daoPledgeService.directPushPage(request.toMp(), request.getDaoId(), request.getTargetUserTel(), request.getSourceUserTel()));
    }

}
